#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;

int N, M;
int G[105][105];
bool T[105][105];
int LEN[105][105];

struct Edge {
	int u, v, w;
	Edge(): u(-1), v(-1), w(0) {
	}
	Edge(int u, int v, int w): u(u), v(v), w(w) {
	}
};

struct Edge_Greater {
	bool operator () (const Edge lhs, const Edge rhs) const {
		return lhs.w > rhs.w;
	}
};

priority_queue<Edge, vector<Edge>, Edge_Greater> Queue;
int FL[105];

int Kruskal() {
	for (int i=1; i<=N; i++) {
		FL[i] = i;
	}
	memset(LEN, 0, sizeof(LEN));
	memset(T, 0, sizeof(T));
	int ans = 0;
	int cnt = 0;
	while (!Queue.empty() && cnt < N-1) {
		Edge e = Queue.top(); Queue.pop();
		int u = e.u; int v = e.v; int w = e.w; 
		if (FL[u] == FL[v]) {
			continue;
		}
		ans += w;
		T[u][v] = T[v][u] = true;
		int flu = FL[u]; int flv = FL[v];
		for (int i=1; i<=N; i++) {
			if (FL[i] == flu) {
				for (int j=1; j<=N; j++) {
					if (FL[j] == flv) {
						LEN[i][j] = LEN[j][i] = w;
					}
				} 
			}
		}
		for (int i=1; i<=N; i++) {
			if (FL[i] == flv) {
				FL[i] = flu;
			}
		}
	}
	return ans;
}

int main() {
	int K;
	scanf("%d", &K);
	while (K--) {
		scanf("%d%d", &N, &M);
		memset(G, 0x3F, sizeof(G));
		while (!Queue.empty())
			Queue.pop();
		for (int i=0; i<M; i++) {
			int x, y, w;
			scanf("%d%d%d", &x, &y, &w);
			G[x][y] = G[y][x] = w;
			Queue.push(Edge(x, y, w));
		}
		int ans = Kruskal();
		int sec = 0x3F3F3F3F;
		for (int i=1; i<=N; i++) {
			for (int j=i; j<=N; j++) {
				if (G[i][j] < 0x3F3F3F3F && (!T[i][j])) {
					int n = ans + G[i][j] - LEN[i][j];
					if (n < sec) sec = n;
				}
			}
		}
		if (sec == ans) printf("Not Unique!\n");
		else printf("%d\n", ans);
	}
	return 0;
}
